package org.springframework.beans.factory;

/**
 *
 * 容器销毁时会调用该方法
 *
 * 被bean实现的接口，在销毁时释放资源。如果销毁一个缓存的单例，一个BeanFactory 可能会调用这个销毁方法。
 *
 * 容器关闭是，应用上下文会销毁所有的单例bean。
 *
 * 一种替代实现DisposableBean 接口的方案为指定一个自定义的destroy-method方法，例如在一个xml bean定义中。
 *
 * Interface to be implemented by beans that want to release resources
 * on destruction. A BeanFactory is supposed to invoke the destroy
 * method if it disposes a cached singleton. An application context
 * is supposed to dispose all of its singletons on close.
 *
 * <p>An alternative to implementing DisposableBean is specifying a custom
 * destroy-method, for example in an XML bean definition.
 * For a list of all bean lifecycle methods, see the BeanFactory javadocs.
 *
 * @author Juergen Hoeller
 * @since 12.08.2003
 * @see org.springframework.beans.factory.support.RootBeanDefinition#getDestroyMethodName
 * @see org.springframework.context.ConfigurableApplicationContext#close
 */
public interface DisposableBean {

	/**
	 * Invoked by a BeanFactory on destruction of a singleton.
	 * @throws Exception in case of shutdown errors.
	 * Exceptions will get logged but not rethrown to allow
	 * other beans to release their resources too.
	 */
	void destroy() throws Exception;

}
